import { getGameObjectById } from "../engine";
import { Behaviour } from "../engine/Behaviour";
import { Transform } from "../engine/Transform";
import { number } from "../engine/validators/number";
import { defeatScene4Binding } from "./defeatScene4Binding";
import { RigidBody } from "./RigidBody";

export class KeepFollow extends Behaviour {

     time=0
    onStart() {

        
    }

    onTick(duringTime: number) {

        if(getGameObjectById('PauseBackGround')===undefined){
        this.time+=duringTime*60/1000}
        else{
            if(getGameObjectById('PauseBackGround').active===true){
            }
            else{
                this.time+=duringTime*60/1000
            }
        }
        
        console.log(this.time)
        const Alice=getGameObjectById("Alice")
        const AliceTransform=Alice.getBehaviour(Transform)
        const transform = this.gameObject.getBehaviour(Transform);
        
        if(this.gameObject.children[0].id==="Monster"){
            transform.x=AliceTransform.x-700+this.time*0.4;
        }
        if(this.time>=1250){

            const currentScene=getGameObjectById('Scene4')
            const parent=currentScene.parent.parent
            const damageScene4 = new defeatScene4Binding()
            const nextScene = this.gameObject.engine.createNewPrefab(damageScene4)
            parent.removeChild(currentScene)
            // parent.removeAllChildren();
            parent.addChild(nextScene)
        }

    }
}
